<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<style>
a:link{text-decoration:none;}
a:visited{text-decoration:none;}
a:hover{text-decoration:underline;}
a:active{text-decoration:none;}
</style>
<html>
	<head> 
	<title>Kqi指标配置</title>
	<jsp:include page="/include.jsp"/>
	<script type="text/javascript">
	//新增
	function doAdd(){
		window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/dqm/basemgr/kqiManager/kqi_add.jsp',
			top:($(window.top).height()-500)*0.5,
			left:($(window.top).width()-900)*0.5,
			width:1000,
			height:500,
			modal:true,
			title:'新增基础指标',
			buttons:[{
				id:'btnSave',
				text:'保 存',
				iconCls:'',
				handler:function(){
					var d=window.top.$(this).closest('.window-body');
					if(window.top.$('#main_form').form('validate'))
					{
						if(window.top.validateKqiValue())
						{
							window.top.$('#main_form').form('submit',{
								url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!addKqi.action',
								onSubmit:function(){
									window.top.$.messager.progress({
										title : '提示',
										text : '正在保存，请稍后 ....'
										});
								},
								success:function(result){
									try {
										var r=$.parseJSON(result);
										//显示提示信息
										window.top.$.messager.show({title:'提示',msg:r.returnMsg});
										
										window.top.$('#main_form').form('clear');//清空form表单
										
										window.top.$("#kpi_sql_validcontent").hide();//隐藏展示列信息的div
										
										 $('#btnSave').linkbutton('disable');//让保存按钮置灰
										//刷新主列表
										$('#table_datagrid').datagrid('reload');
										
										window.top.$.messager.progress('close');//关闭进度条
									} catch (e) {
										window.top.$.messager.progress('close');
										window.top.$.messager.alert('提示', result);
									}
								}
							});
						}
					}
				}
			}],
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
	}
	//修改
	function doEdit(id){
		$.ajax({
			url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!ValidKqiIdRule.action',
			dataType:'json',
			data:{kqiid:id},
			success:function(data){
				if(data.returnFlag){
					$.messager.show({
						title:'操作提示',
						msg:'该指标正在被使用，不能修改'
					});
				}else{
					window.top.$('<div/>').dialog({
						href:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!getKqiByid.action?id='+id,
						top:($(window.top).height()-500)*0.5,
						left:($(window.top).width()-900)*0.5,
						width:1000,
						height:500,
						modal:true,
						title:'修改基础指标',
						buttons:[{
							id:'btnSave',
							text:'保 存',
							iconCls:'',
							handler:function(){
								var d=window.top.$(this).closest('.window-body');
								if(window.top.$('#main_form').form('validate'))
								{
									if(window.top.validateKqiValue())
									{
										window.top.$('#main_form').form('submit',{
											url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!editKqi.action?id='+id,
											onSubmit:function(){
												window.top.$.messager.progress({
													title : '提示',
													text : '正在保存，请稍后 ....'
													});
											},
											success:function(result){
												try {
													var r=$.parseJSON(result);
													//显示提示信息
													window.top.$.messager.show({title:'提示',msg:r.returnMsg});
													//关闭新增窗口
													d.dialog('destroy'); 
													//刷新主列表
													$('#table_datagrid').datagrid('reload');
													
													window.top.$.messager.progress('close');
												} catch (e) {
													window.top.$.messager.progress('close');
													window.top.$.messager.alert('提示', result);
												}
											}
										});
									}
								}
							}
						}],
						onClose:function(){
							window.top.$(this).dialog('destroy');
						}
					});
				}
			}
			}); 
	}
	//删除
	function doRemoveWithConfirm(id){
		$.ajax({
			url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!ValidKqiIdRule.action',
			dataType:'json',
			data:{kqiid:id},
			success:function(data){
				if(data.returnFlag){
					$.messager.show({
						title:'操作提示',
						msg:data.returnMsg
					});
				}else{
					window.top.$.messager.confirm('提示','是否确定删除该指标？',function(b){
						if(b){
							$.ajax({
								url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!deleteKqiById.action',
								dataType:'json',
								data:{id:id},
								success:function(data){
									window.top.$.messager.show({title:'提示',msg:data.returnMsg});
									$('#table_datagrid').datagrid('reload');		
								}
							});
						}
					});
				}
			}
			}); 
	}
	function doRemoveWithoutConfirm(id){
			$.ajax({
				url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!deleteKqiById.action',
				dataType:'json',
				data:{id:id},
				success:function(data){
					window.top.$.messager.show({title:'提示',msg:data.returnMsg});
					$('#table_datagrid').datagrid('reload');
				}
			});
	}
	//删除前检查
	function deleteCheck(){
		var rows=$('#table_datagrid').datagrid('getSelections');
		var id;
		if(rows.length!=1){
			window.top.$.messager.alert('提示', '请选择一条数据！');
			return;
		}else{
			id=rows[0].kqiid;
			$.ajax({
				url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!deleteCheck.action',
				dataType:'json',
				data:{id:id},
				success:function(data){
					if(data==false){
						window.top.$.messager.alert('提示','该指标已经配置了检查规则，请先删除相应检查规则后再删除指标！');
						return;
					}else{
						doRemoveWithConfirm(id);
					}
				}
			}); 
		}
	}
	//详细
	function doDetail(id){
		window.top.$('<div/>').dialog({
			href:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!detailKqiByid.action?id='+id,
			top:($(window.top).height()-500)*0.5,
			left:($(window.top).width()-900)*0.5,
			width:1000,
			height:500,
			modal:true,
			title:'基础指标详细信息',	
			buttons:[{
				text:'关 闭',
				iconCls:'',
				handler:function(){
					var d=window.top.$(this).closest('.window-body');
					d.dialog('destroy'); 
				}
			}],
			onClose:function(){
				window.top.$(this).dialog('destroy');
			}
		});
	}
	//执行查询
	function doQuery(){
		var kqiname=$('#kqinameQ').val();
		var periodtype=$('#periodtypeQ').combobox('getValue');
		var datalevel=$('#datalevelQ').combobox('getValue');
		var query={kqiname:kqiname,periodtype:periodtype,datalevel:datalevel}; //把查询条件拼接成JSON
		if($('#query_form').form('validate'))
		{
			$('#table_datagrid').datagrid('options').queryParams=query; //把查询条件赋值给datagrid内部变量
			$('#table_datagrid').datagrid('load'); //重新加载
		}
	}
	//重置查询条件
	function doReset(){
		$('#kqinameQ').val('');
		$('#periodtypeQ').combobox('setValue',null);
		$('#datalevelQ').combobox('setValue',null);
	}
	//页面加载完后响应 onReady
	$(function() {
		//新增按纽绑定事件
		$('#add').bind('click',doAdd);
		//删除按纽绑定事件
		$('#btnRemove').bind('click',deleteCheck);
		//查询按纽绑定事件
		$('#btnQuery').bind('click',doQuery);
		//重置按纽绑定事件
		$('#btnReset').bind('click',doReset);
		//初始化下拉框
		$('#periodtypeQ').combobox({
			url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!getDic.action?dictType=periodType&list=list',  
			valueField:'codeValue',
			textField:'codeName',
			required: false,
			editable:false,
			onLoadSuccess:function(){
				$('#periodtypeQ').combobox('setValue',null);
			}
		});
		$('#datalevelQ').combobox({
			url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!getDic.action?dictType=dataLevel&list=list',  
			valueField:'codeValue',
			textField:'codeName',
			required: false,
			editable:false,
			onLoadSuccess:function(){
				$('#datalevelQ').combobox('setValue',null);
			}
		});
		//初始化主列表
		$('#table_datagrid').datagrid({
			url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!getAllKqiList.action',
			fit:true,
			border:false,
			fitColumns:true,
			pagination:true,
			striped:true,
			pageList:[10,20,30],
			rownumbers:false,
			sortName:'createtime',
			sortOrder:'desc',			
			columns:[[{field:'kqiid',title:'KQIID',width:80,checkbox:true},
					{field:'kqiIdShow',title:'指标编码',width:60,align:'center'},
					{field:'kqiname',title:'指标名称',width:180,align:'left',
						formatter:function(value,rowData,rowIndex){
							return '<a title="'+rowData.kqiname+'" onclick="doDetail('+rowData.kqiid+')"  style="color:#2b76b7;cursor:pointer;">'+rowData.kqiname+'</a>';
					}},
					{field:'kqiversionnum',title:'版本号',width:80,align:'center'},
					{field:'periodtype',title:'指标周期',width:80,align:'center'},
					{field:'datalevel',title:'数据提取层',width:150,align:'center'},
					{field:'creator',title:'创建者',width:100,align:'center'},
					{field:'createtime',title:'创建时间',width:150,align:'center'},
					{field:'action',title:'操 作',width:150,align:'left',formatter:function (value,row,index){
						return '<span  style="cursor:pointer" onclick="doEdit(\''+row.kqiid+'\')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="修改" alt="修改"/>修改&nbsp;&nbsp;</span>'
							+'<span  style="cursor:pointer" onclick="doRemoveWithConfirm(\''+row.kqiid+'\')"><img  src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除" style="margin-top:2px;"/>删除&nbsp;&nbsp;</span>';
					}
					}]],
			toolbar:'#toolbar',
			onLoadSuccess:function(){
				var kqiNameDiv=$("td[field='kqiname'] div");//如果kqiName的内容太长，则由...代替
				kqiNameDiv.css({
					"white-space":"nowrap",
					"text-overflow":"ellipsis",
					"-o-text-overflow":"ellipsis",
					"overflow":"hidden"
				});
			}
		});
	});
</script>
<body class="easyui-layout">
	<form id="query_form" method="post">
		<div data-options="region:'north'" style="height:80px;border-bottom:none;border-top:none;">
			<table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" >
			<tr>
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label for="kqinameQ">指标名称：</label>
				</td>
				<td style="text-align:left;width:15%;" nowrap="nowrap">
					<input type="text" id="kqinameQ" name="kqinameQ" validType="specialCharFilter('kqinameQ')" class="easyui-validatebox"/>
				</td>
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label for="periodtypeQ">指标周期：</label>
				</td>
				<td style="text-align:left;width:15%;" nowrap="nowrap">
					<input id="periodtypeQ" type="text" class="easyui-combobox" name="periodtypeQ" panelHeight="auto"/>
				</td>
				<td style="text-align:right;width:10%;" nowrap="nowrap">
					<label for="datalevelQ">数据提取层：</label>
				</td>
				<td style="text-align:left;width:15%;padding-right:35px" nowrap="nowrap">
					<input id="datalevelQ" type="text" class="easyui-combobox" name="datalevelQ" panelHeight="auto" />
				</td>
				<td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap">
					<input type="button" id="btnQuery" value="查 询" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;"/>
					<input type="button" id="btnReset" value="重 置" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:35px"/>
				</td>
				</tr>
			</table>
		</div>  
		<div data-options="region:'center'" style="border-top:none">
			<table id="table_datagrid"> 
			</table>
			<div id="toolbar" class="etl_panel_title">
				<a id="add" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true"  style="float:left">新 增</a>
			</div>
		</div>
	</form>
</body>
</html>

